﻿@page "/counter"
@rendermode InteractiveServer
@attribute [TabItemOption(Text = "Counter")]
@attribute [UserNavigation("counter")]

<PageTitle>Counter</PageTitle>
<GroupBox Title="您的连接信息">
    <p class="code-label">本服务已内置 IP 地理位置定位功能，详细配置与文档请参考 <a href="locator" target="_blank">IpLocatorFactory</a></p>

    <div class="row g-3 form-inline">
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Id" DisplayText="连接 ID" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.RequestUrl" DisplayText="请求地址" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Ip" DisplayText="IP 地址" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.City" DisplayText="城市" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.OS" DisplayText="操作系统" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Browser" DisplayText="浏览器" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Engine" DisplayText="浏览器引擎" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Device" DisplayText="设备" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="_clientInfo.Language" DisplayText="语言" ShowLabel="true" />
        </div>
        <div class="col-12">
            <Display Value="_clientInfo.UserAgent" DisplayText="UserAgent" ShowLabel="true" ShowTooltip="true" />
        </div>
    </div>
</GroupBox>
<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }
[Inject]
[NotNull]
private WebClientService? ClientService { get; set; }

private ClientInfo _clientInfo = new();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    await base.OnAfterRenderAsync(firstRender);

    if (firstRender)
    {
        _clientInfo = await ClientService.GetClientInfo();
        StateHasChanged();
    }
}
}
